Fix handling of image-only buttons. (#332985, Kalle Vahlmann, #333555)
authorMatthias Clasen <mclasen@redhat.com>
Mon, 6 Mar 2006 03:47:06 +0000 (03:47 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 6 Mar 2006 03:47:06 +0000 (03:47 +0000)
2006-03-05  Matthias Clasen  <mclasen@redhat.com>

Fix handling of image-only buttons.  (#332985, Kalle
Vahlmann, #333555)

* gtk/gtkbutton.c (gtk_button_construct_child): Don't
return early if there an image to show.
(show_image): Always return TRUE if there is no text.

gtk/gtkbutton.c

index 93f433dfa75553025871a7dbb6640e9ac8227400..0d70bfa8930ede3a41eb1cc40c04e00f978dacc6 100644 (file)
@@ -677,10 +677,17 @@ gtk_button_new (void)
 static gboolean
 show_image (GtkButton *button)
 {
-  GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (button));  
   gboolean show;
+  
+  if (button->label_text)
+    {
+      GtkSettings *settings;
 
-  g_object_get (settings, "gtk-button-images", &show, NULL);
+      settings = gtk_widget_get_settings (GTK_WIDGET (button));        
+      g_object_get (settings, "gtk-button-images", &show, NULL);
+    }
+  else
+    show = TRUE;
 
   return show;
 }
@@ -698,26 +705,25 @@ gtk_button_construct_child (GtkButton *button)
   
   if (!button->constructed)
     return;
-  
-  if (button->label_text == NULL)
+  if (!button->label_text && !priv->image)
     return;
-
-  if (GTK_BIN (button)->child)
-    {
-      if (priv->image && !priv->image_is_stock)
-       {
-         image = g_object_ref (priv->image);
-         if (image->parent)
-           gtk_container_remove (GTK_CONTAINER (image->parent), image);
-       }
-
-      gtk_container_remove (GTK_CONTAINER (button),
-                           GTK_BIN (button)->child);
   
+  if (priv->image && !priv->image_is_stock)
+    {
+      image = g_object_ref (priv->image);
+      if (image->parent)
+       gtk_container_remove (GTK_CONTAINER (image->parent), image);
+      
       priv->image = NULL;
     }
   
+  if (GTK_BIN (button)->child)
+    gtk_container_remove (GTK_CONTAINER (button),
+                         GTK_BIN (button)->child);
+  
   if (button->use_stock &&
+      button->label_text &&
       gtk_stock_lookup (button->label_text, &item))
     {
       if (!image)
@@ -730,9 +736,6 @@ gtk_button_construct_child (GtkButton *button)
 
   if (image)
     {
-      label = gtk_label_new_with_mnemonic (label_text);
-      gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
-      
       priv->image = image;
 
       g_object_set (priv->image, 
@@ -747,7 +750,15 @@ gtk_button_construct_child (GtkButton *button)
        align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
        
       gtk_box_pack_start (GTK_BOX (hbox), priv->image, FALSE, FALSE, 0);
-      gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+      if (label_text)
+       {
+         label = gtk_label_new_with_mnemonic (label_text);
+         gtk_label_set_mnemonic_widget (GTK_LABEL (label), 
+                                        GTK_WIDGET (button));
+
+         gtk_box_pack_end (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+       }
       
       gtk_container_add (GTK_CONTAINER (button), align);
       gtk_container_add (GTK_CONTAINER (align), hbox);
@@ -758,7 +769,7 @@ gtk_button_construct_child (GtkButton *button)
       return;
     }
   
- if (button->use_underline)
 if (button->use_underline)
     {
       label = gtk_label_new_with_mnemonic (button->label_text);
       gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
@@ -768,7 +779,7 @@ gtk_button_construct_child (GtkButton *button)
   
   if (priv->align_set)
     gtk_misc_set_alignment (GTK_MISC (label), priv->xalign, priv->yalign);
-
+  
   gtk_widget_show (label);
   gtk_container_add (GTK_CONTAINER (button), label);
 }